<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CustomerLogin
 *
 * @author tuankiet
 */
class CustomerLoginController extends AppController {
    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('index');
        $this->loadModel('Customers');
    }
    public function index() {
        
        $this->layout = 'login';
        if ($this->Auth->login()){
            return $this->redirect($this->Auth->redirect());
            exit;
        }
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                if ($this->Session->read('lastUrl')) {
                    $this->redirect($this->Session->read('lastUrl'));
                    $this->Session->delete('lastUrl');
                    exit;
                } else
                    return $this->redirect('/home/index');
            } else {
                $this->Session->setFlash(
                        __(' ログインID／パスワードに誤りがあります。'), 'default', array(), 'Auth'
                );
            }
        }
        
    }
    public function logout(){
        return $this->redirect($this->Auth->logout());
    }

    //put your code here
}
